package com.tth.learn.addproperties.java;

import org.junit.Test;

/**
 * 枚举类的使用
 * 方式二：使用enum关键字
 *      说明：定义的枚举类默认继承于java.lang.Enum
 * @Author tth
 * @Date 2022/12/8 10:42
 */
public class SeasonTest1 {
    /**
     * 测试方法
     */
    @Test
    public void test1() {
        Season1 summer = Season1.SUMMER;
        System.out.println(summer.toString());
    }

    @Test
    public void test2() {
        Season1[] season1s = Season1.values();
        for (int i = 0; i < season1s.length; i++) {
            System.out.print(season1s[i]+" ");
        }
    }

    @Test
    public void test3() {
        Season1 spring = Season1.valueOf("SPRING");
        System.out.println(spring);
    }
}

interface Info {
    void show();
}
/**
 * 使用enum关键字定义枚举类
 */
enum Season1 implements Info{
    // 1.提供当前枚举类的对象，多个对象之间用“,”隔开，末尾对象用“;”结束
    SPRING(1001, "春天", "春暖花开"){
        @Override
        public void show() {
            System.out.println("春眠不觉晓");
        }
    },
    SUMMER(1002, "夏天", "烈日炎炎"){
        @Override
        public void show() {
            System.out.println("接天莲叶无穷碧");
        }
    },
    AUTUMN(1003, "秋天", "瓜果飘香"){
        @Override
        public void show() {
            System.out.println("千里共婵娟");
        }
    },
    WINTER(1004, "冬天", "白雪皑皑"){
        @Override
        public void show() {
            System.out.println("墙角数枝梅");
        }
    };

    // 2.声明季节的属性
    private final Integer seasonCode;
    private final String seasonName;
    private final String seasonDesc;

    // 3.私有化构造器
    Season1(Integer seasonCode, String seasonName, String seasonDesc) {
        this.seasonCode = seasonCode;
        this.seasonName = seasonName;
        this.seasonDesc = seasonDesc;
    }

    // 4.其他诉求1：生成季节属性的getter，以获取Season对象实例的属性
    public Integer getSeasonCode() {
        return seasonCode;
    }

    public String getSeasonName() {
        return seasonName;
    }

    public String getSeasonDesc() {
        return seasonDesc;
    }

}

